34
Inheritance
•Inheritance allows to implement the a-kind-of and is-a relationships.
•Classes which are a-kind-of another class share properties of the latter.
•In the point and circle example, it can be defined as a circle which inherits from point.
class Circle inherits from Point {
attributes:
int radius
methods:
setRadius(int newRadius)
getRadius()
}
Class Circle inherits all data elements and methods from point. There is no need to define them twice.